#! /bin/bash
source ../variable.sh 

rm -f *.rpm
#rpmlist="containernetworking-plugins protobuf zlib-devel vim-filesystem vim-common libnetfilter_queue libnetfilter_cttimeout libnetfilter_cthelper gpm-libs vim-enhanced emacs-filesystem protobuf-devel protobuf-c conntrack-tools-help conntrack-tools criu socat libcgroup runc containerd docker-cli docker kubernetes-client kubernetes-kubeadm kubernetes-master kubernetes-kubelet kubernetes-node"
rpmlist="criu libcgroup protobuf zlib-devel vim-filesystem vim-common libnetfilter_queue libnetfilter_cttimeout libnetfilter_cthelper gpm-libs vim-enhanced emacs-filesystem protobuf-devel protobuf-c conntrack-tools-help conntrack-tools socat"
rpmlist_cloud="runc containerd docker-cli docker kubernetes-kubelet kubernetes-client kubernetes-node kubernetes-kubeadm kubernetes-master containernetworking-plugins"

sudo yum makecache

#Download rpms for rpmlist
for a in ${arch[@]}; do
    for d in ${dist[@]}; do
        yum download --repo=$d --repo=${d}-update --forcearch=$a $rpmlist
    done
done

#Download rpms for rpmlist_cloud based on different versions set in variable.sh
versions=(set_version_120 set_version_125 set_version_129)

for version in ${versions[@]}; do
    $version  # Call the function to set the environment variables

    for a in ${arch[@]}; do
        for d in ${dist[@]}; do
            for pkg in $rpmlist_cloud; do
                version_var=$(echo "${pkg^^}" | tr '-' '_')_VERSION  # Convert package name to uppercase and append _VERSION
                version_var=${!version_var}                           # Dereference to get the version
                if [[ ! -z "$version_var" ]]; then
                    yum download --repo=$d --repo=${d}-update --forcearch=$a "${pkg}-${version_var}"
                else
                    echo "No version specified for $pkg, skipping..."
                fi
            done
        done
    done
done
